/*
===========================================================================
This source file is part of DyLab (Dynamic Laboratory)
For the latest info, see http://dylab.googlecode.com

Copyright (c) 2006-2008 Lukas Krejci
(krejci.lukas@volny.cz)

This file is part of DyLab.

    DyLab is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DyLab is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DyLab.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

#ifndef __dylab_EAssertionFailed_h__
#define __dylab_EAssertionFailed_h__

//===========================================================================================
#include <dylab/utils/exceptions/ExceptionBase.h>

//===========================================================================================
namespace dylab {

    /**
     *
     */
    class DYLAB_EXPORT EAssertionFailed
        : public ExceptionBase<EAssertionFailed>
    {
    public:

        EAssertionFailed()
                { }

        EAssertionFailed(const String & _message)
            : ExceptionBase<EAssertionFailed>(_message)
                { }
    };
}

//===========================================================================================
// assert macro
#if defined(DYLAB_BUILD_DEBUG) || (DYLAB_FORCE_ASSERT_CHECKING == 1)
#   define DYLAB_ASSERT(c)			if (!(c)) throw dylab::EAssertionFailed(dylab::String::fmt("Assertion failed: '%1%' (%2%, %3%)", #c, __FILE__, __LINE__))
#   define DYLAB_ASSERT_MSG(c, m)	if (!(c)) throw dylab::EAssertionFailed(dylab::String::fmt("Assertion failed: '%1%' (%3%, %4%) :'%2%'", #c, m, __FILE__, __LINE__))
#   define DYLAB_ASSERT_MSGF(c, f, v)				DYLAB_ASSERT_MSG(c, dylab::String::fmt(f, v))
#   define DYLAB_ASSERT_MSGF2(c, f, v1, v2)			DYLAB_ASSERT_MSG(c, dylab::String::fmt(f, v1, v2))
#   define DYLAB_ASSERT_MSGF3(c, f, v1, v2, v3)		DYLAB_ASSERT_MSG(c, dylab::String::fmt(f, v1, v2, v3))
#   define DYLAB_ASSERT_MSGF4(c, f, v1, v2, v3, v4) DYLAB_ASSERT_MSG(c, dylab::String::fmt(f, v1, v2, v3, v4))
#else
#   define DYLAB_ASSERT(c) 
#   define DYLAB_ASSERT_MSG(c, m)   
#   define DYLAB_ASSERT_MSGF(c, f, m)
#   define DYLAB_ASSERT_MSGF2(c, f, v1, v2)
#   define DYLAB_ASSERT_MSGF3(c, f, v1, v2, v3)
#   define DYLAB_ASSERT_MSGF4(c, f, v1, v2, v3, v4)
#endif

//===========================================================================================
#endif // __dylab_EAssertionFailed_h__
